package edu.tms.dao;

import java.util.List;
import java.util.Map;

import edu.tms.bean.CharacterRole;
import edu.tms.crud.JdbcUtil;
import edu.tms.dao.common.CommnonDao;
/**
 * 人物角色表dao
 * @author Administrator
 *
 */
@SuppressWarnings("rawtypes")
public class CharacterRoleDaoImp implements CommnonDao{
	/**
	 * 保存内容
	 * @param value
	 * @return 
	 * @throws Exception
	 */
	@Override
	public long save(Object value) throws Exception {
		//判断类   instanceof 
		CharacterRole cr=null;
		if(value instanceof CharacterRole){
			cr=(CharacterRole)value;
			String sql="INSERT INTO t_character_role(char_id,role_name,char_role_state)values(?,?,?)";
			long Number=JdbcUtil.insertAuto(sql,
					cr.getCharId(),
					cr.getRoleName(),
					cr.getCharRoleState()
					);
			return Number;
		}
		return 0;
	}
	/**
	 * 修改内容
	 * @param value
	 * @throws Exception
	 */
	@Override
	public int update(Object value) throws Exception {
		CharacterRole cr=null;
		if(value instanceof CharacterRole){
			cr=(CharacterRole)value;
			String sql="UPDATE t_character_role SET char_id=?,role_name=?,character_role_state=? where char_role_id=?";
			int Number=JdbcUtil.update(sql,
					cr.getCharId(),
					cr.getRoleName(),
					cr.getCharRoleState(),
					cr.getCharRoleId());
			return Number;
		}
		return 0;
	}
	
	/**
	 * 删除内容
	 * 学生表 t_student
	 * @param value
	 * @throws Exception
	 */
	@Override
	public int delete(Object value) throws Exception {
		CharacterRole cr=null;
		if(value instanceof CharacterRole){
			cr=(CharacterRole)value;
			String sql="DELETE FROM t_character_role WHERE char_role_id=? or char_id=? or role_name=?;";
			int Number=JdbcUtil.update(sql,
					cr.getCharRoleId(),
					cr.getCharId(),
					cr.getRoleName()
					);
			return Number;
		}
		return 0;
	}
	/**
	 * 查找所有的内容
	 * @param pageNo 第几页
	 * @param pageSize 每页数字
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<CharacterRole> findAll(int pageNo, int pageSize) throws Exception {
		String sql="select * from t_character_role limit ?,?";
		return JdbcUtil.query(CharacterRole.class,sql,(pageNo-1)*pageSize,pageSize);
	}
	
	/**
	 * 查找有关关键字的所有内容
	 * @param key 关键字
	 * @param pageNo 第几页
	 * @param pageSize 每页数字
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<CharacterRole> findAll(Object key) throws Exception {
		return JdbcUtil.query(CharacterRole.class,
				"select * from t_character_role where char_id = ? or "
				+ "role_name = ? ",
				key, key);
		
	}
	
	/**
	 * 查找有关关键字的所有内容
	 * @param key 关键字
	 * @param pageNo 第几页
	 * @param pageSize 每页数字
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<CharacterRole> findAll(Object key, int pageNo, int pageSize) throws Exception {
		return JdbcUtil.query(CharacterRole.class,
				"select * from t_character_role where char_id = ? or "
				+ "role_name = ? or character_role_state = ? limit ?,?",
				key, key, key,(pageNo-1)*pageSize,pageSize);
		
	}
	

	/**
	 * String 对应  数据库 列名（comment)
	 * Object 对应相应列名值
	 * 返回的是所查找的类中的数据。方便EXCEL导出
	 */
	@Override
	public List<Map<String,Object>> getMapList() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	@Override
	public Object findByKey(Object key) throws Exception {
		return null;
	}



}
